class TeamRecord(object):
    
    def __init__(self):
        self.v = 0
        self.d = 0
        self.l = 0
        self.gs = 0
        self.ga = 0
    
    def get_match_number(self):
        return self.v + self.d + self.l
    
    m = property(get_match_number)
    
    def get_points(self):
        return 3 * self.v + self.d
    
    p = property(get_points)

    def get_goal_diff(self):
        return self.gs - self.ga
    
    gd = property(get_goal_diff)

    def update_with_match(self, match):
        f, a = match
        if f > a:
            self.v += 1
        elif f < a:
            self.l += 1
        else:
            self.d += 1
        self.gs += f
        self.ga += a
    
    def __str__(self):
        return 'M %d, P %d, V %d, E %d, D %d, GS %d, GA %d, GD %d' %\
                (self.m, self.p, self.v, self.d, self.l, self.gs, self.ga,
                 self.gd)


class Standings(object):
    
    def __init__(self, teams):
        self.teams = dict(teams)
        self.records = dict([(n, TeamRecord()) for n in self.teams])
        
    def update_with_match(self, match):
        for match_team in (match.match_team1, match.match_team2):
            if match_team.team.name not in self.teams:
                print ('Match %s cannot be added to standings because %s is not in '
                       'Standings') % (match, match_team.team)

        record1 = self.records[match.match_team1.team.name]
        record2 = self.records[match.match_team2.team.name]
        record1.update_with_match((match.score1, match.score2))
        record2.update_with_match((match.score2, match.score1))
        
    def __getitem__(self, i):
        return self.records.get(i, None)
